﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class ServiceDao
    {
        public bool insert(Service service)
        {
            object[,] param = {
                {"@ServiceTypeId", service.ServiceTypeId},
                {"@Name", service.Name},
                {"@Price", service.Price},
                {"@Desc", service.Desc},
            };
            String sql = "insert into SERVICES(SVT_ID, SVC_NAME, SVC_PRICE ,SVC_DESC) " +
                "values(@ServiceTypeId, @Name, @Price, @Desc)";
            return DB.exec(sql, param);
        }

        public bool update(Service service)
        {
            object[,] param = {
                {"@ServiceTypeId", service.ServiceTypeId},
                {"@Name", service.Name},
                {"@Price", service.Price},
                {"@Desc", service.Desc},
                {"@id", service.Id},
            };
            String sql = "update SERVICES set SVT_ID = @ServiceTypeId, SVC_NAME = @Name, SVC_PRICE SVC_DESC = @Price " +
                "where SVC_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from SERVICES where SVC_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from SERVICES where SVC_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from SERVICES where SVC_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from SERVICES order by SVC_NAME";
            return DB.getData(sql);
        }

        public DataTable getByServiceType(int serviceTypeId)
        {
            object[,] param = {
                {"@SVT_ID", serviceTypeId}   
            };
            String sql = "select * from SERVICES where SVT_ID = @SVT_ID";
            return DB.getData(sql, param);
        }
    }
}
